package com.lnt.spring.dependencies;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 循环依赖测试类1
 * 先创建CircularServiceTest1,执行CircularServiceTest1的声明周期：
 * 1.实例化CircularServiceTest1 ---- >得到一个CircularServiceTest1对象
 * 2.填充CircularServiceTest1的属性 ---- > 去单例池中去找CircularServiceTest2 ----> 没有则创建
 * 3.填充其他属性
 * 4.初始化前，初始化
 * 5.初始化后
 * 6.放入单例池
 */
@Component
public class CircularServiceTest1 {

    @Autowired
    private CircularServiceTest2 circularServiceTest2;

    public void test(){
        System.out.println(circularServiceTest2);
    }

    @Override
    public String toString() {
        return "CircularServiceTest1纳入bean容器管理:" +
                "\n 1.创建CircularServiceTest1:" +
                "\n \t || 将CircularServiceTest1放入一个createSet中表示该对象正在被创建" +
                "\n \t || 实例化CircularServiceTest1 ---->得到一个对象" +
                "\n \t || 将上边得到的对象放入singletonFactory<beanName(String), lambda(原始对象/AOP代理对象)>[三级缓存]中" +
                "\n 2.填充CircularServiceTest1的属性:" +
                "\n \t || 发现CircularServiceTest1中存在另一个bean对象CircularServiceTest2" +
                "\n \t || 去单例池中去拿取CircularServiceTest2对象,若存在，则赋值，不存在则创建CircularServiceTest2" +
                "\n====================================================" +
                "\n \t " + circularServiceTest2.toString() +
                "\n 3. 填充其他属性" +
                "\n 4. 初始化前" +
                "\n 5. 初始化" +
                "\n 6. 初始化后" +
                "\n 7.完成创建,将CircularServiceTest1放入到单例池SingletonObject[一级缓存]中" +
                "\n --------------------------------END---------------------------------";
    }
}
